﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using WMS.Common;
using WMS.RepositoryDefinitions.Dto;
using WMS.Suppliers;
using WMS.Suppliers.DTO;

namespace WMS.Suppliers
{
    public class SupplierServices : ApplicationService, ISupplierServices
    {
        private readonly IRepository<Supplier, int> _repository;

        public SupplierServices(IRepository<Supplier, int> repository)
        {
            this._repository = repository;
        }

        public Task<int> AddRepository(Supplierdto repositoryDefinitionDto)
        {
            throw new NotImplementedException();
        }

        public Task<int> DeleteRepository(int id)
        {
            throw new NotImplementedException();
        }

        public Task<Supplierdto> GetRepositoryInfo(int id)
        {
            throw new NotImplementedException();
        }

        public Task<PagedResult> GetRepositoryList(string? repositoryCode, int page = 1, int limit = 10)
        {
            throw new NotImplementedException();
        }

        public Task<int> UpdateRepository(Supplierdto repositoryDefinitionDto)
        {
            throw new NotImplementedException();
        }

        //public async Task<int> AddRepository(RepositoryDefinitionDto repositoryDefinitionDto)
        //{
        //    var repositoryCode = _repository.AnyAsync(m => m.SupplierName == repositoryDefinitionDto.RepositoryCode).Result;
        //    if (repositoryCode)
        //    {
        //        return -1;
        //    }

        //    var repositoryName = _repository.AnyAsync(m => m.SupplierName == repositoryDefinitionDto.RepositoryName).Result;
        //    if (repositoryName)
        //    {
        //        return -1;
        //    }

        //    var repositoryModel = repositoryDefinitionDto.MapTo<RepositoryDefinition>();
        //    await _repository.InsertAsync(repositoryModel);
        //    return repositoryDefinitionDto.Id;
        //}

        //public async Task<PagedResult> GetRepositoryList(string? repositoryCode, int page = 1, int limit = 10)
        //{
        //    var predicate = PredicateBuilder.New<RepositoryDefinition>(true);
        //    if (!string.IsNullOrEmpty(repositoryCode))
        //    {
        //        predicate = predicate.And(m => m.RepositoryCode.Contains(repositoryCode));
        //    }
        //    var dto = _repository.GetListAsync(predicate).Result;
        //    PagedResult result = new PagedResult();
        //    result.PageCount = (int)Math.Ceiling((decimal)(dto.Count == 0 ? 1 : dto.Count) / limit);
        //    result.PageSize = limit;
        //    result.CurrentPage = page;
        //    result.RowCount = dto.Count;
        //    result.Queryable = dto.Skip((page - 1) * limit).Take(limit).AsQueryable();
        //    return result;
        //}

        //public async Task<int> DeleteRepository(int id)
        //{
        //    await _repository.DeleteAsync(id);
        //    return 1;
        //}

        //public async Task<RepositoryDefinitionDto> GetRepositoryInfo(int id)
        //{
        //    var entity = _repository.GetAsync(id).Result;
        //    var repositoryDefinitionDto = ObjectMapper.Map<RepositoryDefinition, RepositoryDefinitionDto>(entity);
        //    return repositoryDefinitionDto;
        //}

        //public async Task<int> UpdateRepository(RepositoryDefinitionDto repositoryDefinitionDto)
        //{
        //    var repositoryName = await _repository.AnyAsync(m => m.SupplierName == repositoryDefinitionDto.RepositoryName && m.Id != repositoryDefinitionDto.Id);

        //    RepositoryDefinition repositoryDefinition = repositoryDefinitionDto.MapTo<RepositoryDefinition>();
        //    await _repository.UpdateAsync(repositoryDefinition);
        //    return repositoryDefinition.Id;
        //}
    }
}
